<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 本地存储 setItem getItem
        // sessionStorage 生命周期 会话级别
        // window.sessionStorage.setItem('msg','zhangsan');
        // localStorage 生命周期 永久
        // window.localStorage.setItem('msg','lisi');

        let userData = {username: 'tom',age:22,gender : false,birthday : '1999-09-19'};

        // JSON.stringify(object) 将对象转成json字符串的方法
        window.sessionStorage.setItem('user',JSON.stringify(userData));

        // getItem
        // JSON.parse 解析一个JSON字符串
        let data = window.sessionStorage.getItem('user');
        console.log(JSON.parse(data).username);

        // 删除
        window.sessionStorage.removeItem('user');

        // let a;
        // console.log(a);
    </script>
</body>
</html>